package com.java110.mall.goods.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.product.ProductServKeywordDto;
import com.java110.mall.goods.bmo.productServKeyword.IDeleteProductServKeywordBMO;
import com.java110.mall.goods.bmo.productServKeyword.IGetProductServKeywordBMO;
import com.java110.mall.goods.bmo.productServKeyword.ISaveProductServKeywordBMO;
import com.java110.mall.goods.bmo.productServKeyword.IUpdateProductServKeywordBMO;
import com.java110.po.product.ProductServKeywordPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/productServKeyword")
public class ProductServKeywordApi {

    @Autowired
    private ISaveProductServKeywordBMO saveProductServKeywordBMOImpl;
    @Autowired
    private IUpdateProductServKeywordBMO updateProductServKeywordBMOImpl;
    @Autowired
    private IDeleteProductServKeywordBMO deleteProductServKeywordBMOImpl;

    @Autowired
    private IGetProductServKeywordBMO getProductServKeywordBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /productServKeyword/saveProductServKeyword
     * @path /app/productServKeyword/saveProductServKeyword
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveProductServKeyword", method = RequestMethod.POST)
    public ResponseEntity<String> saveProductServKeyword(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "keywordId", "请求报文中未包含keywordId");
        Assert.hasKeyAndValue(reqJson, "keywordName", "请求报文中未包含keywordName");
        Assert.hasKeyAndValue(reqJson, "keywordType", "请求报文中未包含keywordType");
        Assert.hasKeyAndValue(reqJson, "objId", "请求报文中未包含objId");


        ProductServKeywordPo productServKeywordPo = BeanConvertUtil.covertBean(reqJson, ProductServKeywordPo.class);
        return saveProductServKeywordBMOImpl.save(productServKeywordPo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /productServKeyword/updateProductServKeyword
     * @path /app/productServKeyword/updateProductServKeyword
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateProductServKeyword", method = RequestMethod.POST)
    public ResponseEntity<String> updateProductServKeyword(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "keywordId", "请求报文中未包含keywordId");
        Assert.hasKeyAndValue(reqJson, "keywordName", "请求报文中未包含keywordName");
        Assert.hasKeyAndValue(reqJson, "keywordType", "请求报文中未包含keywordType");
        Assert.hasKeyAndValue(reqJson, "objId", "请求报文中未包含objId");
        Assert.hasKeyAndValue(reqJson, "keywordId", "keywordId不能为空");


        ProductServKeywordPo productServKeywordPo = BeanConvertUtil.covertBean(reqJson, ProductServKeywordPo.class);
        return updateProductServKeywordBMOImpl.update(productServKeywordPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /productServKeyword/deleteProductServKeyword
     * @path /app/productServKeyword/deleteProductServKeyword
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteProductServKeyword", method = RequestMethod.POST)
    public ResponseEntity<String> deleteProductServKeyword(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺ID不能为空");

        Assert.hasKeyAndValue(reqJson, "keywordId", "keywordId不能为空");


        ProductServKeywordPo productServKeywordPo = BeanConvertUtil.covertBean(reqJson, ProductServKeywordPo.class);
        return deleteProductServKeywordBMOImpl.delete(productServKeywordPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /productServKeyword/queryProductServKeyword
     * @path /app/productServKeyword/queryProductServKeyword
     * @param shopId 小区ID
     * @return
     */
    @RequestMapping(value = "/queryProductServKeyword", method = RequestMethod.GET)
    public ResponseEntity<String> queryProductServKeyword(@RequestParam(value = "shopId") String shopId,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        ProductServKeywordDto productServKeywordDto = new ProductServKeywordDto();
        productServKeywordDto.setPage(page);
        productServKeywordDto.setRow(row);
        productServKeywordDto.setShopId(shopId);
        return getProductServKeywordBMOImpl.get(productServKeywordDto);
    }
}
